<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/15
 * Time: 17:44
 */

namespace App\apitransifer;


use League\Fractal\TransformerAbstract;
use Modules\Shop\Entities\Article;

class ArticleTransfer extends TransformerAbstract
{
    //定义一个include可使用的字段
    protected $availableIncludes = ['category'];
    public function transform(Article $article)
    {
        return [
            'id'=> $article['id'],
            'title'=> $article['title'],
            'thumb'=> $article['thumb'],
            'jieshao'=>  $article['jieshao'],
            'content' => $article['content'],
        ];
    }

    public function includeCategory(Article $article){
        return $this->item($article->category,new CategoryTransformer());
    }
}